package com.dc.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    //自定义视图跳转  将一个请求直接映射为视图
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //浏览器发送/main.html请求 ， 就会跳转到index页面；
        registry.addViewController("/main.html").setViewName("index");


    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自定义的拦截器，配置拦截路径     拦截哪个路径下 不包括...的请求（除了登录，静态资源...）
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin","/admin/login");
    }

}
